<template>
  <div class="main">

    <div class="left">
      <el-menu
      :default-active="$route.fullPath"
      text-color="#fff"
      background-color="#545c64"
      active-text-color="#ffd04b"
      router
      class="menu"
      >
      <el-menu-item index="/admin/user">
        <i class="el-icon-menu"></i>
        <span slot="title">用户管理</span>
      </el-menu-item>
      <el-menu-item index="/admin/good">
        <i class="el-icon-menu"></i>
        <span slot="title">商品管理</span>
      </el-menu-item>
      <el-menu-item index="/admin/order">
        <i class="el-icon-menu"></i>
        <span slot="title">订单管理</span>
      </el-menu-item>
      <el-menu-item index="/admin/type">
        <i class="el-icon-menu"></i>
        <span slot="title">类别管理</span>
      </el-menu-item>
      <el-menu-item index="/admin/coupon">
        <i class="el-icon-menu"></i>
        <span slot="title">优惠券管理</span>
      </el-menu-item>
      <el-menu-item index="/admin/sessions">
        <i class="el-icon-menu"></i>
        <span slot="title">会话管理</span>
      </el-menu-item>
    </el-menu>
    </div>
    <div class="right">
      <div class="top">

        <div class="top-left">商店管理中心</div>
        <div class="top-right">
          <el-dropdown @command="command_handler">
            <span class="el-dropdown-link">
              {{ name }}<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :command="1">修改密码</el-dropdown-item>
              <el-dropdown-item :command="2">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        
      </div>
      <div class="mod">
        <router-view></router-view>
      </div>
    </div>
    

  </div>

</template>
<script>
import { logout } from '@/api/user_api';

export default{
  data(){
    return{
      name:""
    }
  },
  methods:{
    command_handler(Param){
      switch(Param){
        case 1:
          this.$router.push("/admin/pwd")
          break
        case 2:
            this.$confirm('确定退出登录', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(async () => {
              const {data:res} = await logout()
              this.$message({
                type: res.code==200?'success':'error',
                message: res.message
              });
              if(res.code==200){
                localStorage.clear()
                this.$router.push('/')
              }
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消'
              });          
            });
          break
      }
    }
  
  },
  created(){
    this.name =  JSON.parse(localStorage.getItem('user')).username
  }

}
</script>
<style scoped lang="scss">
.main{
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  display: flex;
  .left{
    height: 100%;
    width: 15%;
    .menu{
      height: 100%;
    }
  }
  .right{
    width: 85%;
    height: 100%;
    .top{
      background-color: #f2f2f2;
      height: 10%;
      font-weight: bold;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .top-left{
        padding-left: 5%;
        font-size: 40px;
      }
      .top-right{
        cursor: pointer;
        margin-right: 5%;
      }
    }
    .mod{
      margin: 5%;
      height: 80%;
      overflow-y: scroll;
    }

  }
}
</style>